<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const img = document.querySelector('img');
        const loadImg = (img) => { // 加载图片
            img.src = img.dataset.src;
        }
        // 创建IntersectionObserver实例，监听图片是否进入视口
        const io = new IntersectionObserver((entries) => {
            entries.forEach((e) => e.isIntersecting && loadImg(e.target));
        });
        io.observe(img); // 监听图片是否进入视口
    </script>
</body>
</html>
